package resman.bean;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import resman.model.Bean;

@SuppressWarnings("serial")
@Entity
@Table(name = "Resume")
public class ResumeBean extends Bean
{
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private long resumeId;

	@OneToOne(mappedBy = "resume", cascade = CascadeType.ALL)
	private LoginBean login;

	@OneToOne(mappedBy = "resume", cascade = CascadeType.ALL)
	private PersonalBean personal;

	@OneToMany(mappedBy = "resume", cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
	private Set<GradBean> grads;

	@OneToMany(mappedBy = "resume", cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
	private Set<PostGradBean> postGrads;

	@OneToMany(mappedBy = "resume", cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
	private Set<CompBean> comps;

	@OneToMany(mappedBy = "resume", cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
	private Set<ProfBean> profs;

	@OneToMany(mappedBy = "resume", cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
	private Set<ArticleBean> articles;

	@OneToMany(mappedBy = "resume", cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
	private Set<BookBean> books;

	@OneToMany(mappedBy = "resume", cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
	private Set<TextBean> texts;

	public ResumeBean()
	{
		grads = new HashSet<GradBean>();
		postGrads = new HashSet<PostGradBean>();
		comps = new HashSet<CompBean>();

		profs = new HashSet<ProfBean>();

		articles = new HashSet<ArticleBean>();
		books = new HashSet<BookBean>();
		texts = new HashSet<TextBean>();
	}

	public long getResumeId()
	{
		return resumeId;
	}

	public void setResumeId(long resumeId)
	{
		this.resumeId = resumeId;
	}

	public LoginBean getLogin()
	{
		return login;
	}

	public void setLogin(LoginBean login)
	{
		this.login = login;
	}

	public PersonalBean getPersonal()
	{
		return personal;
	}

	public void setPersonal(PersonalBean personal)
	{
		this.personal = personal;
	}

	public Set<ArticleBean> getArticles()
	{
		return articles;
	}
	
	public ArticleBean getArticle(int articleId)
	{
		for (ArticleBean article : articles)
			if (article.getArticleId() == articleId)
				return article;
		return null;
	}

	public void setArticles(Set<ArticleBean> articleSet)
	{
		this.articles = articleSet;
	}

	public Set<BookBean> getBooks()
	{
		return books;
	}
	
	public BookBean getBook(int bookId)
	{
		for (BookBean book : books)
			if (book.getBookId() == bookId)
				return book;
		return null;
	}

	public void setBooks(Set<BookBean> bookSet)
	{
		this.books = bookSet;
	}

	public Set<CompBean> getComps()
	{
		return comps;
	}
	
	public CompBean getComp(int compId)
	{
		for (CompBean comp : comps)
			if (comp.getCompId() == compId)
				return comp;
		return null;
	}

	public void setComps(Set<CompBean> compSet)
	{
		this.comps = compSet;
	}

	public Set<GradBean> getGrads()
	{
		return grads;
	}
	
	public GradBean getGrad(int gradId)
	{
		for (GradBean grad : grads)
			if (grad.getGradId() == gradId)
				return grad;
		return null;
	}

	public void setGrads(Set<GradBean> gradSet)
	{
		this.grads = gradSet;
	}

	public Set<PostGradBean> getPostGrads()
	{
		return postGrads;
	}
	
	public PostGradBean getPostGrad(int postGradId)
	{
		for (PostGradBean postGrad : postGrads)
			if (postGrad.getPostGradId() == postGradId)
				return postGrad;
		return null;
	}

	public void setPostGrads(Set<PostGradBean> postgradSet)
	{
		this.postGrads = postgradSet;
	}

	public Set<ProfBean> getProfs()
	{
		return profs;
	}
	
	public ProfBean getProf(int profId)
	{
		for (ProfBean prof : profs)
			if (prof.getProfId() == profId)
				return prof;
		return null;
	}

	public void setProfs(Set<ProfBean> profSet)
	{
		this.profs = profSet;
	}

	public Set<TextBean> getTexts()
	{
		return texts;
	}
	
	public TextBean getText(int textId)
	{
		for (TextBean text : texts)
			if (text.getTextId() == textId)
				return text;
		return null;
	}

	public void setTexts(Set<TextBean> textSet)
	{
		this.texts = textSet;
	}
}
